var requestHandler = {
  params: {},
  API_URL: '',
  token: '',
  success: function (res) {
    // success  
  },
  fail: function () {
    // fail  
  },
}

//GET请求   

function GET(requestHandler) {
  request('GET', requestHandler)
}
//POST请求  
function POST(requestHandler) {
  request('POST', requestHandler)
}

function request(method, requestHandler) { 
  let params = requestHandler.params;
  if(params){
    params.appid = 'wxd2b40ab306d86d08';
  }
  let API_URL = requestHandler.API_URL;
  wx.request({
    url: `https://api.1lianyou.com/${API_URL}`,
    // url: `http://47.110.229.171:2022/${API_URL}`,
    data: params || '',
    method: method,
    timeout: 10000,
    header: {
      'content-type': 'application/json'
    }, // 设置请求的 header  
    success: function (res) {
      // if (res.statusCode == 404 || res.statusCode == 500) {
      //   wx.showToast({
      //     title: '网络错误，请退出后再试',
      //   })
      //   return;
      // }
      //注意：可以对参数解密等处理  
      // console.log('返回:',res)
      requestHandler.success(res)
    },
    fail: function () {
      requestHandler.fail()
    },
    complete: function () {
      // complete  
    }
  })
}

module.exports = {
  GET: GET,
  POST: POST
}